package com.xique.park.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xique.common.core.utils.DateUtils;
import com.xique.common.core.utils.StringUtils;
import com.xique.park.bean.domain.ParkGarage;
import com.xique.park.bean.search.web.ParkGarageLaneDevListSearch;
import com.xique.park.mapper.ParkGarageMapper;
import com.xique.park.service.service.IParkGarageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 车库Service业务层处理
 *
 * @author xique
 * @date 2021-12-09
 */
@Service
public class ParkGarageServiceImpl extends ServiceImpl<ParkGarageMapper, ParkGarage> implements IParkGarageService {

    @Autowired
    private ParkGarageMapper parkGarageMapper;

    /**
     * 查询车库
     *
     * @param id 车库ID
     * @return 车库
     */
    @Override
    public ParkGarage selectParkGarageById(Long id) {
        return parkGarageMapper.selectById(id);
    }

    /**
     * 查询车库列表
     *
     * @param parkGarage 车库
     * @return 车库
     */
    @Override
    public List<ParkGarage> selectParkGarageList(Long parkId, ParkGarage parkGarage) {
        QueryWrapper<ParkGarage> wrapper = new QueryWrapper<>();
        wrapper.eq(null != parkId, "park_id", parkId);
        wrapper.eq("record_status", "normal");
        wrapper.eq(StringUtils.isNotEmpty(parkGarage.getType()), "type", parkGarage.getType());
        return parkGarageMapper.selectList(wrapper);
    }

    /**
     * 新增车库
     *
     * @param parkGarage 车库
     * @return 结果
     */
    @Override
    public int insertParkGarage(ParkGarage parkGarage) {
        parkGarage.setCreateTime(DateUtils.getNowDate());
        return parkGarageMapper.insert(parkGarage);
    }

    /**
     * 修改车库
     *
     * @param parkGarage 车库
     * @return 结果
     */
    @Override
    public int updateParkGarage(ParkGarage parkGarage) {
        parkGarage.setUpdateTime(DateUtils.getNowDate());
        return parkGarageMapper.updateById(parkGarage);
    }

    /**
     * 批量删除车库
     *
     * @param ids 需要删除的车库ID
     * @return 结果
     */
    @Override
    public int deleteParkGarageByIds(List<Long> ids) {
        return parkGarageMapper.deleteBatchIds(ids);
    }

    /**
     * 删除车库信息
     *
     * @param id 车库ID
     * @return 结果
     */
    @Override
    public int deleteParkGarageById(Long id) {
        return parkGarageMapper.deleteById(id);
    }

    @Override
    public List<Map<String, Object>> getGarageLaneDevList(ParkGarageLaneDevListSearch search) {
        return parkGarageMapper.getGarageLaneDevList(search);
    }

    @Override
    public List<ParkGarage> selectParkGarageByName(String parkGarageName, Long parkId) {
        return parkGarageMapper.selectParkGarageByName(parkGarageName, parkId);
    }

    @Override
    public List<ParkGarage> selectParkGarageByParkId(long parkId) {
        return parkGarageMapper.selectByParkId(parkId);
    }
}
